extends ../../../../app/views/layout-marketing

mixin launchpad-check(section)
	div(data-ol-launchpad-check=section)
		span(data-ol-inflight="pending")
			i.fa.fa-fw.fa-spinner.fa-spin
			span &nbsp;#{translate('checking')}
	
		span(hidden data-ol-inflight="idle")
			div(data-ol-result="success")
				i.fa.fa-check
				span &nbsp;#{translate('ok')}
				button.btn.btn-inline-link
					span.text-danger &nbsp;#{translate('retry')}
			div(hidden data-ol-result="error")
				i.fa.fa-exclamation
				span &nbsp;#{translate('error')}
				button.btn.btn-inline-link
					span.text-danger &nbsp;#{translate('retry')}
				div.alert.alert-danger
					span(data-ol-error)

block vars
	- entrypoint = 'modules/launchpad/pages/launchpad'
	- metadata = metadata || {}

block append meta
	meta(name="ol-adminUserExists" data-type="boolean" content=adminUserExists)
	meta(name="ol-ideJsPath" content=buildJsPath('ide.js'))

block content
	script(type="text/javascript", nonce=scriptNonce, src=(wsUrl || '/socket.io') + '/socket.io.js')

	.content.content-alt
		.container(ng-cloak)
			.row
				.col-md-8.col-md-offset-2
					.card.launchpad-body
						.row
							.col-md-12
								.text-center
									h1 #{translate('welcome_to_sl')}
									p
										img(src=buildImgPath('/ol-brand/overleaf-o.svg'))

						<!-- wrapper -->
						.row
							.col-md-8.col-md-offset-2


								<!-- create first admin form -->
								if !adminUserExists
									.row(data-ol-not-sent)
										.col-md-12
											h2 #{translate('create_first_admin_account')}

											// Local Auth Form
											if authMethod === 'local'
												form(
													data-ol-async-form
													data-ol-register-admin
													action="/launchpad/register_admin"
													method="POST"
												)
													input(name='_csrf', type='hidden', value=csrfToken)
													+formMessages()
													.form-group
														label(for='email') #{translate("email")}
														input.form-control(
															type='email',
															name='email',
															placeholder="email@example.com"
															required,
															autofocus="true"
														)
													.form-group
														label(for='password') #{translate("password")}
														input.form-control#passwordField(
															type='password',
															name='password',
															placeholder="********",
															required,
														)
													.actions
														button.btn-primary.btn(
															type='submit'
															data-ol-disabled-inflight
														)
															span(data-ol-inflight="idle") #{translate("register")}
															span(hidden data-ol-inflight="pending") #{translate("registering")}…

											// Ldap Form
											if authMethod === 'ldap'
												h3 #{translate('ldap')}
												p
													| #{translate('ldap_create_admin_instructions')}

												form(
													data-ol-async-form
													data-ol-register-admin
													action="/launchpad/register_ldap_admin"
													method="POST"
												)
													input(name='_csrf', type='hidden', value=csrfToken)
													+formMessages()
													.form-group
														label(for='email') #{translate("email")}
														input.form-control(
															type='email',
															name='email',
															placeholder="email@example.com"
															required,
															autofocus="true"
														)
													.actions
														button.btn-primary.btn(
															type='submit'
															data-ol-disabled-inflight
														)
															span(data-ol-inflight="idle") #{translate("register")}
															span(hidden data-ol-inflight="pending") #{translate("registering")}…

											// Saml Form
											if authMethod === 'saml'
												h3 #{translate('saml')}
												p
													| #{translate('saml_create_admin_instructions')}

												form(
													data-ol-async-form
													data-ol-register-admin
													action="/launchpad/register_saml_admin"
													method="POST"
												)
													input(name='_csrf', type='hidden', value=csrfToken)
													+formMessages()
													.form-group
														label(for='email') #{translate("email")}
														input.form-control(
															type='email',
															name='email',
															placeholder="email@example.com"
															required,
															autofocus="true"
														)
													.actions
														button.btn-primary.btn(
															type='submit'
															data-ol-disabled-inflight
														)
															span(data-ol-inflight="idle") #{translate("register")}
															span(hidden data-ol-inflight="pending") #{translate("registering")}…

									br

								<!-- status indicators -->
								if adminUserExists
									.row
										.col-md-12.status-indicators

											h2 #{translate('status_checks')}

											<!-- ide js -->
											.row.row-spaced-small
												.col-sm-5
													| #{translate('editor_resources')}
												.col-sm-7
													+launchpad-check('ide')

											<!-- websocket -->
											.row.row-spaced-small
												.col-sm-5
													| #{translate('websockets')}
												.col-sm-7
													+launchpad-check('websocket')

									<!-- break -->
									hr.thin

									<!-- other actions -->
									.row
										.col-md-12
											h2 #{translate('other_actions')}

											h3 #{translate('send_test_email')}
											form.form(
												data-ol-async-form
												action="/launchpad/send_test_email"
												method="POST"
											)
												.form-group
													label(for="email") Email
													input.form-control(
														type="text"
														id="email"
														name="email"
														required
													)
												button.btn-primary.btn(
													type='submit'
													data-ol-disabled-inflight
												)
													span(data-ol-inflight="idle") #{translate("send")}
													span(hidden data-ol-inflight="pending") #{translate("sending")}…

												p
													+formMessages()



									<!-- break -->
									hr.thin


									<!-- Go to app -->
									.row
										.col-md-12
											.text-center
												br
												p
													a(href="/admin").btn.btn-info
														| Go To Admin Panel
													| &nbsp;
													a(href="/project").btn.btn-primary
														| Start Using #{settings.appName}
												br
